**********************************************************
** Title: Are voters’ views about proportional outcomes **
** shaped by partisan preferences? 						**
** A survey experiment in the context of a real election**			
** By: André Blais, Semra Sevi and Carolina Plescia		**											
** Purpose:	replication analyses manuscript and sm		**
** Journal:												**
** Data:	CES 2019									**
** Date:	February 2020			 					**
**********************************************************

/* This do-file replicates all the analyses that are reported in the manuscript
and the supplementary materials of "Are voters’ views about proportional outcomes 
	shaped by partisan preferences? A survey experiment in the context of a real election */

use "CES2019 Campaign Period Survey Blais module data 2020-01-10.dta"

svyset[pweight=cps19_weight_general]

rename blais_con_1_FPTP_1 con_fptp_1
rename blais_con_2_FPTP_1 con_fptp_2
rename blais_con_3_FPTP_1 con_fptp_3
rename blais_con_1_PR_1 con_pr_1
rename blais_con_2_PR_1 con_pr_2
rename blais_con_3_PR_1 con_pr_3
rename blais_lib_1_FPTP_1 lib_fptp_1
rename blais_lib_2_FPTP_1 lib_fptp_2
rename blais_lib_3_FPTP_1 lib_fptp_3
rename blais_lib_1_PR_1 lib_pr_1
rename blais_lib_2_PR_1 lib_pr_2
rename blais_lib_3_PR_1 lib_pr_3
rename blais_ndp_1_FPTP_1 ndp_fptp_1
rename blais_ndp_2_FPTP_1 ndp_fptp_2
rename blais_ndp_3_FPTP_1 ndp_fptp_3
rename blais_ndp_1_PR_1 ndp_pr_1
rename blais_ndp_2_PR_1 ndp_pr_2
rename blais_ndp_3_PR_1 ndp_pr_3
rename blais_grn_1_FPTP_1 grn_fptp_1
rename blais_grn_2_FPTP_1 grn_fptp_2
rename blais_grn_3_FPTP_1 grn_fptp_3
rename blais_grn_1_PR_1 grn_pr_1
rename blais_grn_2_PR_1 grn_pr_2
rename blais_grn_3_PR_1 grn_pr_3

*Appendix B
svy: mean con_fptp_1
svy: mean con_fptp_2
svy: mean con_fptp_3
svy: mean con_pr_1
svy: mean con_pr_2
svy: mean con_pr_3
svy: mean lib_fptp_1
svy: mean lib_fptp_2
svy: mean lib_fptp_3
svy: mean lib_pr_1
svy: mean lib_pr_2
svy: mean lib_pr_3
svy: mean ndp_fptp_1
svy: mean ndp_fptp_2
svy: mean ndp_fptp_3
svy: mean ndp_pr_1
svy: mean ndp_pr_2
svy: mean ndp_pr_3
svy: mean grn_fptp_1
svy: mean grn_fptp_2
svy: mean grn_fptp_3
svy: mean grn_pr_1
svy: mean grn_pr_2
svy: mean grn_pr_3

*, format(%11.3g) cell count  

*Table 1
gen more_votes_fptp = con_fptp_1 if !missing(con_fptp_1)
replace more_votes_fptp = lib_fptp_1 if !missing(lib_fptp_1)
replace more_votes_fptp = ndp_fptp_1 if !missing(ndp_fptp_1)
replace more_votes_fptp = grn_fptp_1 if !missing(grn_fptp_1)

gen average_vote_fptp = con_fptp_2 if !missing(con_fptp_2)
replace average_vote_fptp = lib_fptp_2 if !missing(lib_fptp_2)
replace average_vote_fptp = ndp_fptp_2 if !missing(ndp_fptp_2)
replace average_vote_fptp = grn_fptp_2 if !missing(grn_fptp_2)

gen fewer_votes_fptp = con_fptp_3 if !missing(con_fptp_3)
replace fewer_votes_fptp = lib_fptp_3 if !missing(lib_fptp_3)
replace fewer_votes_fptp = ndp_fptp_3 if !missing(ndp_fptp_3)
replace fewer_votes_fptp = grn_fptp_3 if !missing(grn_fptp_3)

gen more_votes_pr = con_pr_1 if !missing(con_pr_1)
replace more_votes_pr = lib_pr_1 if !missing(lib_pr_1)
replace more_votes_pr = ndp_pr_1 if !missing(ndp_pr_1)
replace more_votes_pr = grn_pr_1 if !missing(grn_pr_1)

gen average_vote_pr = con_pr_2 if !missing(con_pr_2)
replace average_vote_pr = lib_pr_2 if !missing(lib_pr_2)
replace average_vote_pr = ndp_pr_2 if !missing(ndp_pr_2)
replace average_vote_pr = grn_pr_2 if !missing(grn_pr_2)

gen fewer_votes_pr = con_pr_3 if !missing(con_pr_3)
replace fewer_votes_pr = lib_pr_3 if !missing(lib_pr_3)
replace fewer_votes_pr = ndp_pr_3 if !missing(ndp_pr_3)
replace fewer_votes_pr = grn_pr_3 if !missing(grn_pr_3)

*reshape the dataset
gen obs = _n

reshape long con_fptp_ con_pr_ lib_fptp_ lib_pr_ ///
	ndp_fptp_ ndp_pr_ grn_fptp_ grn_pr_, i(obs) j(votes)

rename con_fptp_ con_0
rename con_pr_ con_1
rename lib_fptp_ lib_0
rename lib_pr_ lib_1
rename ndp_fptp_ ndp_0
rename ndp_pr_ ndp_1
rename grn_fptp_ grn_0
rename grn_pr_	grn_1
	
reshape long con_ lib_ ndp_ grn_ , i(obs votes) j(PR) 

rename con_ satisfaction_1
rename lib_ satisfaction_0
rename ndp_ satisfaction_2
rename grn_ satisfaction_3

reshape long satisfaction_ , i(obs votes PR) j(party)

rename satisfaction_ satisfaction 
recode votes 1=1 2=0 3=-1

label define votes_lab 1 "More" 0 "Average" -1 "Less"
label define pr_lab 0 "FPTP" 1 "PR"
label define party_lab 0 "Lib" 1 "Con" 2 "Ndp" 3 "Grn"

label values votes votes_lab
label values PR pr_lab
label values party party_lab

*create votes variable
order satisfaction votes PR party

*Table 1
svy: mean satisfaction, over(votes) coeflegend
estat sd
test _b[satisfaction:Average] = _b[satisfaction:Less]
test _b[satisfaction:Average] = _b[satisfaction:More]

svy: mean satisfaction, over(PR) coeflegend
estat sd
test _b[satisfaction:FPTP] = _b[satisfaction:PR]

gen ndp_grn = party 
recode ndp_grn 0 = 0 1 = 0 2 = 1 3 = 1
label define ndp_grn_lab 0 "LIB/CON" 1 "NDP/GRN"
label values ndp_grn ndp_grn_lab


*create raw votes variable
gen raw_votes = .
replace raw_votes = 40 if party == 1 & PR == 0 & votes == 1
replace raw_votes = 34 if party == 1 & PR == 0 & votes == 0
replace raw_votes = 28 if party == 1 & PR == 0 & votes == -1
replace raw_votes = 40 if party == 1 & PR == 1 & votes == 1
replace raw_votes = 34 if party == 1 & PR == 1 & votes == 0
replace raw_votes = 28 if party == 1 & PR == 1 & votes == -1

replace raw_votes = 40 if party == 0 & PR == 0 & votes == 1
replace raw_votes = 34 if party == 0 & PR == 0 & votes == 0
replace raw_votes = 28 if party == 0 & PR == 0 & votes == -1
replace raw_votes = 40 if party == 0 & PR == 1 & votes == 1
replace raw_votes = 34 if party == 0 & PR == 1 & votes == 0
replace raw_votes = 28 if party == 0 & PR == 1 & votes == -1

replace raw_votes = 19 if party == 2 & PR == 0 & votes == 1
replace raw_votes = 13 if party == 2 & PR == 0 & votes == 0
replace raw_votes = 7  if party == 2 & PR == 0 & votes == -1
replace raw_votes = 19 if party == 2 & PR == 1 & votes == 1
replace raw_votes = 13 if party == 2 & PR == 1 & votes == 0
replace raw_votes = 7  if party == 2 & PR == 1 & votes == -1

replace raw_votes = 17 if party == 3 & PR == 0 & votes == 1
replace raw_votes = 11 if party == 3 & PR == 0 & votes == 0
replace raw_votes = 5  if party == 3 & PR == 0 & votes == -1
replace raw_votes = 17 if party == 3 & PR == 1 & votes == 1
replace raw_votes = 11 if party == 3 & PR == 1 & votes == 0
replace raw_votes = 5  if party == 3 & PR == 1 & votes == -1

*create plurality variables 
gen plurality = .
replace plurality = 1 if party == 1 & PR == 0 & votes == 1
replace plurality = 0 if party == 1 & PR == 0 & votes == 0
replace plurality = 0 if party == 1 & PR == 0 & votes == -1
replace plurality = 1 if party == 1 & PR == 1 & votes == 1
replace plurality = 0 if party == 1 & PR == 1 & votes == 0
replace plurality = 0 if party == 1 & PR == 1 & votes == -1

replace plurality = 1 if party == 0 & PR == 0 & votes == 1
replace plurality = 1 if party == 0 & PR == 0 & votes == 0
replace plurality = 0 if party == 0 & PR == 0 & votes == -1
replace plurality = 1 if party == 0 & PR == 1 & votes == 1
replace plurality = 0 if party == 0 & PR == 1 & votes == 0
replace plurality = 0 if party == 0 & PR == 1 & votes == -1

replace plurality = 0 if party == 2 & PR == 0 & votes == 1
replace plurality = 0 if party == 2 & PR == 0 & votes == 0
replace plurality = 0 if party == 2 & PR == 0 & votes == -1
replace plurality = 0 if party == 2 & PR == 1 & votes == 1
replace plurality = 0 if party == 2 & PR == 1 & votes == 0
replace plurality = 0 if party == 2 & PR == 1 & votes == -1

replace plurality = 0 if party == 3 & PR == 0 & votes == 1
replace plurality = 0 if party == 3 & PR == 0 & votes == 0
replace plurality = 0 if party == 3 & PR == 0 & votes == -1
replace plurality = 0 if party == 3 & PR == 1 & votes == 1
replace plurality = 0 if party == 3 & PR == 1 & votes == 0
replace plurality = 0 if party == 3 & PR == 1 & votes == -1


*rescale the party ratings 
gen LP_rating = (cps19_party_rating_23)/100
gen CPC_rating = (cps19_party_rating_24)/100
gen NDP_rating = (cps19_party_rating_25)/100
gen Bloc_rating = (cps19_party_rating_26)/100
gen Grn_rating = (cps19_party_rating_27)/100
gen PPC_rating = (cps19_party_rating_28)/100

*reshape to find the highest rating
rename LP_rating rating0
rename CPC_rating rating1
rename NDP_rating rating2
rename Grn_rating rating3
rename Bloc_rating rating4
rename PPC_rating rating5
label define partyrating_lab 0 "Lib" 1 "Con" 2 "Ndp" 3 "Grn" 4 "Bloc" 5 "PPC"
reshape long rating, i(obs votes PR party) j(rating_party)
label values rating_party partyrating_lab 
sort obs votes PR party rating
by obs votes PR party : egen rating_count = count(rating)
by obs votes PR party : gen rating_margin = rating[rating_count] - rating[rating_count -1] 
reshape wide rating, i(obs votes PR party) j(rating_party)
drop rating_count
rename rating0 LP_rating 
rename rating1 CPC_rating 
rename rating2 NDP_rating 
rename rating3 Grn_rating 
rename rating4 Bloc_rating 
rename rating5 PPC_rating 
gen strong_rating = rating_margin >= .15 if !missing(rating_margin)
label define strong_rating_lab 0 "Weak" 1 "Strong"
label values strong_rating strong_rating_lab


*Table 2 
*regression
eststo clear
eststo m1: reg satisfaction raw_votes i.PR i.party [pw=cps19_weight_general], cluster(obs)
eststo m2: reg satisfaction raw_votes i.PR i.party plurality [pw=cps19_weight_general], cluster(obs)
eststo m3: reg satisfaction c.raw_votes##i.PR i.party plurality [pw=cps19_weight_general], cluster(obs) 
eststo m4: reg satisfaction raw_votes i.PR##i.party plurality [pw=cps19_weight_general], cluster(obs)

esttab m1 m2 m3 m4 using regressions.rtf, ///
	replace b(3) se(3) ///
	stats(r2 N, fmt(%9.3f)) nogap label compress
	
*Robustness
*Appendix C
eststo clear
eststo m5: reg satisfaction c.votes i.PR i.party [pw=cps19_weight_general], cluster(obs)
eststo m6: reg satisfaction c.votes i.PR i.party plurality [pw=cps19_weight_general], cluster(obs)
eststo m7: reg satisfaction c.votes##i.PR i.party plurality [pw=cps19_weight_general], cluster(obs) 
eststo m8: reg satisfaction votes i.PR##i.party plurality [pw=cps19_weight_general], cluster(obs)

esttab m5 m6 m7 m8 using robustness.rtf, ///
	replace b(3) se(3) ///
	stats(r2 N, fmt(%9.3f)) nogap label compress

*Appendix D
eststo clear
eststo m9: reg satisfaction raw_votes i.PR i.party [pw=cps19_weight_general] if strong_rating==1, cluster(obs)
eststo m10: reg satisfaction raw_votes i.PR i.party plurality [pw=cps19_weight_general] if strong_rating==1, cluster(obs)
eststo m11: reg satisfaction c.raw_votes##i.PR i.party plurality [pw=cps19_weight_general] if strong_rating==1, cluster(obs) 
eststo m12: reg satisfaction raw_votes i.PR##i.party plurality [pw=cps19_weight_general] if strong_rating==1, cluster(obs)

esttab m9 m10 m11 m12 using regressions_strong.rtf, ///
	replace b(3) se(3) ///
	stats(r2 N, fmt(%9.3f)) nogap label compress	

eststo clear
eststo m13: reg satisfaction raw_votes i.PR i.party [pw=cps19_weight_general] if strong_rating==0, cluster(obs)
eststo m14: reg satisfaction raw_votes i.PR i.party plurality [pw=cps19_weight_general] if strong_rating==0, cluster(obs)
eststo m15: reg satisfaction c.raw_votes##i.PR i.party plurality [pw=cps19_weight_general] if strong_rating==0, cluster(obs) 
eststo m16: reg satisfaction raw_votes i.PR##i.party plurality [pw=cps19_weight_general] if strong_rating==0, cluster(obs)

esttab m13 m14 m15 m16 using regressions_weak.rtf, ///
	replace b(3) se(3) ///
	stats(r2 N, fmt(%9.3f)) nogap label compress	




